package org.baoping.mq.listener;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author HeZeMin
 * @className DemoConcumer
 * @description 消息-消费类
 * @date 2021/1/18 10:14
 */
@Slf4j
@EnableBinding({Sink.class})// 绑定 input 消息通道
@Component
public class ConcumerListener {
    /**
     *
     * @Description 消费消息
     * @Return: void
     * @Author HeZeMin
     * @Date 2021年01月18日 10:19
     */
    @StreamListener(value = Sink.INPUT, condition = "headers['tag']=='tag-message'")// 消息监听器
    public void receiveInput1(@Payload Map<String, Object> paramMap) {
        log.info("input receive1: {}", JSONUtil.toJsonStr(paramMap));
    }
    /**
     *
     * @Description 其他 tag 消费类型的消息
     * @Return: void
     * @Author HeZeMin
     * @Date 2021年01月18日 16:03
     */
    @StreamListener(value = Sink.INPUT, condition = "headers['tag']=='tag-demo'")// 消息监听器
    public void receiveInput2(@Payload Map<String, Object> paramMap) {
        log.info("input receive2: {}", JSONUtil.toJsonStr(paramMap));
    }
}